all files / src/validators/ stock.validator.ts

61.54% Statements 8/13
0% Branches 0/2
66.67% Functions 2/3
66.67% Lines 8/12
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20                        
import { Game, Phase } from '../game.interfaces';
import { getUniqueBidders, getBidWinner } from '../helpers/bid.helpers';
import * as _ from 'lodash';
import { ShareStock } from '../game.actions';
import { hasEightCards, getCard } from '../helpers/cards.helpers';
 
export function canShareStock(state: Game, action: ShareStock): boolean {
    if(state.phase !== Phase.SHARE_STOCK) { return false; }
 
    const winnerPlayerId = getBidWinner(state.bid).player;
    const winnerPlayerCards = state.cards[winnerPlayerId];
    
    return !!getCard(winnerPlayerCards, action.card);
}
 
export function isSharingStockFinished(state: Game): boolean {
    return _.chain(getUniqueBidders(state.bid))
        .every(playerId => hasEightCards(state.cards[playerId]))
        .value();
}